#include<bits/stdc++.h>
using namespace std;
class SortedStack {
public:
	stack<int> stk;
	stack<int> helpStk;
	SortedStack() {
	}
	void push(int val) {
		if (stk.empty() || val <= stk.top())
			stk.push(val);
		else {
			while (!stk.empty() && stk.top() < val) {
				helpStk.push(stk.top()); stk.pop();
			}
			stk.push(val);
			while (!helpStk.empty()) {
				stk.push(helpStk.top()); helpStk.pop();
			}
		}

	}

	void pop() {
		stk.pop();
	}

	int peek() {
		if(!stk.empty())
		return stk.top();
		return NULL;
	}

	bool isEmpty() {
		return stk.empty();
	}
};
int main35() {
	SortedStack ss;
	ss.push(1);
	ss.push(2);
	cout << ss.peek() << endl;
	ss.pop();
	cout << ss.peek() << endl;
	return 0;
}
/**
 * Your SortedStack object will be instantiated and called as such:
 * SortedStack* obj = new SortedStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->peek();
 * bool param_4 = obj->isEmpty();
 */